home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / windows / tpwin31.zip / DDEML.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-06  |  14KB  |  449 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal for Windows Run-time Library       }
  5. {       Windows 3.1 API Interface Unit                  }
  6. {                                                       }
  7. {       Copyright (c) 1992 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit ddeml;
  12.  
  13. interface
  14.  
  15. uses WinTypes;
  16.  
  17. type
  18.   HConvList = Longint;
  19.   HConv = Longint;
  20.   HSz = Longint;
  21.   HDDEData = Longint;
  22.  
  23. type
  24.   { the following structure is for use with xtyp_WildConnect processing. }
  25.   PHSZPair = ^THSZPair;
  26.   THSZPair = record
  27.     hszSvc: HSZ;
  28.     hszTopic: HSZ;
  29.   end;
  30.  
  31.   { The following structure is used by DdeConnect() and DdeConnectList()
  32.     and by xtyp_Connect and xtyp_WildConnect callbacks. }
  33.  
  34.   PConvContext = ^TConvContext;
  35.   TConvContext = record
  36.     cb: Word;             { set to sizeof(ConvCOnTEXT) }
  37.     wFlags: Word;         { none currently defined. }
  38.     wCountryID: Word;     { country code for topic/item strings used. }
  39.     iCodePage: Integer;   { codepage used for topic/item strings. }
  40.     dwLangID: Longint;    { language ID for topic/item strings. }
  41.     dwSecurity: Longint;  { Private security code. }
  42.   end;
  43.  
  44. { The following structure is used by DdeQueryConvInfo(): }
  45.  
  46.   PConvInfo = ^TConvInfo;
  47.   TConvInfo = record
  48.     cb: Longint;            { sizeof(CONVINFO)  }
  49.     hUser: Longint;         { user specified field  }
  50.     hConvPartner: HConv;    { hConv on other end or 0 if non-ddemgr partner  }
  51.     hszSvcPartner: HSz;     { app name of partner if obtainable  }
  52.     hszServiceReq: HSz;     { AppName requested for connection  }
  53.     hszTopic: HSz;          { Topic name for conversation  }
  54.     hszItem: HSz;           { transaction item name or NULL if quiescent  }
  55.     wFmt: Word;             { transaction format or NULL if quiescent  }
  56.     wType: Word;            { XTYP_ for current transaction  }
  57.     wStatus: Word;          { ST_ constant for current conversation  }
  58.     wConvst: Word;          { XST_ constant for current transaction  }
  59.     wLastError: Word;       { last transaction error.  }
  60.     hConvList: HConvList;   { parent hConvList if this conversation is in a list }
  61.     ConvCtxt: TConvContext; { conversation context }
  62.   end;
  63.  
  64. const
  65.   { conversation states (usState) }
  66.  
  67.   xst_NULL = 0;                 { quiescent states }
  68.   xst_Incomplete = 1;
  69.   xst_Connected = 2;
  70.   xst_Init1 = 3;                { mid-initiation states }
  71.   xst_Init2 = 4;
  72.   xst_ReqSent = 5;              { active conversation states }
  73.   xst_DataRcvd = 6;
  74.   xst_PokeSent = 7;
  75.   xst_PokeAckRcvd = 8;
  76.   xst_ExecSent = 9;
  77.   xst_ExecAckRcvd = 10;
  78.   xst_AdvSent = 11;
  79.   xst_UnadvSent = 12;
  80.   xst_AdvAckRcvd = 13;
  81.   xst_UnadvAckRcvd = 14;
  82.   xst_AdvDataSent = 15;
  83.   xst_AdvDataAckRcvd = 16;
  84.  
  85.   { used in LOWORD(dwData1) of XTYP_AdvReq callbacks... }
  86.  
  87.   cadv_LateAck = $FFFF;
  88.  
  89.   { conversation status bits (fsStatus) }
  90.  
  91.   st_Connected = $0001;
  92.   st_Advise = $0002;
  93.   st_IsLocal = $0004;
  94.   st_Blocked = $0008;
  95.   st_Client = $0010;
  96.   st_Terminated = $0020;
  97.   st_InList = $0040;
  98.   st_BlockNext = $0080;
  99.   st_IsSelf = $0100;
  100.  
  101.   { DDE constants for wStatus field }
  102.  
  103.   dde_FAck = $8000;
  104.   dde_FBusy = $4000;
  105.   dde_FDeferUpd = $4000;
  106.   dde_FAckReq = $8000;
  107.   dde_FRelease = $2000;
  108.   dde_FRequested = $1000;
  109.   dde_FAckReserved = $3ff0;
  110.   dde_FAdvReserved = $3fff;
  111.   dde_FDatReserved = $4fff;
  112.   dde_FPokReserved = $dfff;
  113.   dde_FAppStatus = $00ff;
  114.   dde_FNotProcessed = $0000;
  115.  
  116.   { message filter hook types }
  117.  
  118.   msgf_DDEMgr = $8001;
  119.  
  120.   { default codepage for windows & old DDE convs. }
  121.  
  122.   cp_WinAnsi = 1004;
  123.  
  124.   { transaction types }
  125.  
  126.   xtypf_NoBlock = $0002; { cbr_Block will not work }
  127.   xtypf_NoData = $0004;  { dde_FDeferUpd }
  128.   xtypf_AckReq = $0008;  { dde_FAckReq }
  129.  
  130.   xclass_Mask = $FC00;
  131.   xclass_Bool = $1000;
  132.   xclass_Data = $2000;
  133.   xclass_Flags = $4000;
  134.   xclass_Notification = $8000;
  135.  
  136.   xtyp_Error = $0000 or xclass_Notification or xtypf_NoBlock;
  137.   xtyp_AdvData = $0010 or xclass_Flags;
  138.   xtyp_AdvReq = $0020 or xclass_Data or xtypf_NoBlock;
  139.   xtyp_AdvStart = $0030 or xclass_Bool;
  140.   xtyp_AdvStop = $0040 or xclass_Notification;
  141.   xtyp_Execute = $0050 or xclass_Flags;
  142.   xtyp_Connect = $0060 or xclass_Bool or xtypf_NoBlock;
  143.   xtyp_Connect_Confirm = $0070 or xclass_Notification or xtypf_NoBlock;
  144.   xtyp_XACT_Complete = $0080 or xclass_Notification;
  145.   xtyp_Poke = $0090 or xclass_Flags;
  146.   xtyp_Register = $00A0 or xclass_Notification or xtypf_NoBlock;
  147.   xtyp_Request = $00B0 or xclass_Data;
  148.   xtyp_Disconnect = $00C0 or xclass_Notification or xtypf_NoBlock;
  149.   xtyp_Unregister = $00D0 or xclass_Notification or xtypf_NoBlock;
  150.   xtyp_WildConnect = $00E0 or xclass_Data or xtypf_NoBlock;
  151.  
  152.   xtyp_Mask = $00F0;
  153.   xtyp_Shift = 4;  { shift to turn xtyp_ into an index }
  154.  
  155.   { Timeout constants }
  156.  
  157.   Timeout_Async =           -1;
  158.  
  159.   { Transaction ID constatnts }
  160.   QID_Sync =                -1;
  161.  
  162.   { public strings used in DDE }
  163.  
  164.   szddesys_Topic = 'System';
  165.   szddesys_Item_Topics = 'Topics';
  166.   szddesys_Item_SysItems = 'SysItems';
  167.   szddesys_Item_RtnMsg = 'ReturnMessage';
  168.   szddesys_Item_Status = 'Status';
  169.   szddesys_Item_Formats = 'Formats';
  170.   szddesys_Item_Help = 'Help';
  171.   szdde_Item_ItemList = 'TopicItemList';
  172.  
  173. type
  174.   { API entry points }
  175.   TCallback = function (CallType, Fmt: Word; Conv: HConv; hsz1, hsz2: HSZ;
  176.     Data: HDDEData; Data1, Data2: Longint): HDDEData;
  177.  
  178. const
  179.   cbr_Block = $ffffffff;
  180.  
  181. { DLL registration functions }
  182.  
  183. function DdeInitialize(var Inst: Longint; Callback: TCallback; Cmd, Res: Longint): Word;
  184.  
  185. const
  186.   { Callback filter flags for use with standard apps. }
  187.  
  188.   cbf_Fail_SelfConnections = $00001000;
  189.   cbf_Fail_Connections = $00002000;
  190.   cbf_Fail_Advises = $00004000;
  191.   cbf_Fail_Executes = $00008000;
  192.   cbf_Fail_Pokes = $00010000;
  193.   cbf_Fail_Requests = $00020000;
  194.   cbf_Fail_AllSrvXActions = $0003f000;
  195.  
  196.   cbf_Skip_Connect_Confirms = $00040000;
  197.   cbf_Skip_Registrations = $00080000;
  198.   cbf_Skip_Unregistrations = $00100000;
  199.   cbf_Skip_Disconnects = $00200000;
  200.   cbf_Skip_AllNotifications = $003c0000;
  201.  
  202.   { Application command flags }
  203.  
  204.   AppCmd_ClientOnly = $00000010;
  205.   AppCmd_FilterInits = $00000020;
  206.   AppCmd_Mask = $00000FF0;
  207.  
  208.   { Application classification flags }
  209.  
  210.   AppClass_Standard = $00000000;
  211.   AppClass_Mask = $0000000F;
  212.  
  213. function DdeUninitialize(Inst: Longint): Bool;
  214.  
  215. { conversation enumeration functions }
  216.  
  217. function DdeConnectList(Inst: Longint; Service, Topic: HSZ;
  218.   ConvList: HConvList; CC: PConvContext): HConvList;
  219. function DdeQueryNextServer(ConvList: HConvList; ConvPrev: HConv): HConv;
  220. function DdeDisconnectList(ConvList: HConvList): Bool;
  221.  
  222. { conversation control functions }
  223.  
  224. function DdeConnect(Inst: Longint; Service, Topic: HSZ;
  225.   CC: PConvContext): HConv;
  226. function DdeDisconnect(Conv: HConv): Bool;
  227. function DdeReconnect(Conv: HConv): HConv;
  228.  
  229. function DdeQueryConvInfo(Conv: HConv; Transaction: Longint;
  230.  ConvInfo: PConvInfo): Word;
  231. function DdeSetUserHandle(Conv: HConv; ID, User: Longint): Bool;
  232.  
  233. function DdeAbandonTransaction(Inst: Longint; Conv: HConv;
  234.   Transaction: Longint): Bool;
  235.  
  236. { app server interface functions }
  237.  
  238. function DdePostAdvise(Inst: Longint; Topic, Item: HSZ): Bool;
  239. function DdeEnableCallback(Inst: Longint; Conv: HConv; Cmd: Word): Bool;
  240.  
  241. const
  242.   ec_EnableAll = 0;
  243.   ec_EnableOne = st_BlockNext;
  244.   ec_Disable = st_Blocked;
  245.   ec_QueryWaiting = 2;
  246.  
  247. function DdeNameService(Inst: Longint; hsz1, hsz2: HSZ;
  248.   Cmd: Word): HDDEData;
  249.  
  250. const
  251.   dns_Register = $0001;
  252.   dns_Unregister = $0002;
  253.   dns_FilterOn = $0004;
  254.   dns_FilterOff = $0008;
  255.  
  256. { app client interface functions }
  257.  
  258. function DdeClientTransaction(Data: Pointer; DataLen: Longint;
  259.   Conv: HConv; Item: HSZ; Fmt, DataType: Word; Timeout: Longint;
  260.   Result: PLongint): HDDEData;
  261.  
  262. { data transfer functions }
  263.  
  264. function DdeCreateDataHandle(Inst: Longint; Src: Pointer;
  265.   cb, Off: Longint; Item: HSZ; Fmt, Cmd: Word): HDDEData;
  266.  
  267. function DdeAddData(Data: HDDEData; Src: Pointer;
  268.   cb, Off: Longint): HDDEData;
  269. function DdeGetData(Data: HDDEData; Dst: Pointer;
  270.   Max, Off: Longint): Longint;
  271. function DdeAccessData(Data: HDDEData; DataSize: PLongint): Pointer;
  272. function DdeUnaccessData(Data: HDDEData): Bool;
  273. function DdeFreeDataHandle(Data: HDDEData): Bool;
  274.  
  275. const
  276.   hdata_AppOwned = $0001;
  277.  
  278. function DdeGetLastError(Inst: Longint): Word;
  279.  
  280.  
  281. const
  282.   { error codes }
  283.  
  284.   dmlErr_No_Error = 0;       { must be 0 }
  285.  
  286.   dmlErr_First = $4000;
  287.  
  288.   dmlErr_AdvAckTimeout = $4000;
  289.   dmlErr_Busy = $4001;
  290.   dmlErr_DataAckTimeout = $4002;
  291.   dmlErr_DLL_Not_Initialized = $4003;
  292.   dmlErr_DLL_Usage = $4004;
  293.   dmlErr_ExecAckTimeout = $4005;
  294.   dmlErr_InvalidParameter = $4006;
  295.   dmlErr_Low_Memory = $4007;
  296.   dmlErr_Memory_Error = $4008;
  297.   dmlErr_NotProcessed = $4009;
  298.   dmlErr_No_Conv_Established = $400a;
  299.   dmlErr_PokeAckTimeout = $400b;
  300.   dmlErr_PostMsg_Failed = $400c;
  301.   dmlErr_Reentrancy = $400d;
  302.   dmlErr_Server_Died = $400e;
  303.   dmlErr_Sys_Error = $400f;
  304.   dmlErr_UnadvAckTimeout = $4010;
  305.   dmlErr_Unfound_Queue_ID = $4011;
  306.  
  307.   dmlErr_Last = $4011;
  308.  
  309. function DdeCreateStringHandle(Inst: Longint; psz: PChar;
  310.   CodePage: Integer): HSZ;
  311. function DdeQueryString(Inst: Longint; HSZ: HSZ; psz: PChar;
  312.   Max: Longint; CodePage: Integer): Longint;
  313. function DdeFreeStringHandle(Inst: Longint; HSZ: HSZ): Bool;
  314. function DdeKeepStringHandle(Inst: Longint; HSZ: HSZ): Bool;
  315. function DdeCmpStringHandles(hsz1, hsz2: HSZ): Integer;
  316.  
  317. type
  318.   { DDEML public debugging header file info }
  319.  
  320.   TMonMsgStruct = record
  321.     cb: Word;
  322.     hWndTo: HWnd;
  323.     dwTime: Longint;
  324.     hTask: THandle;
  325.     wMsg: Word;
  326.     wParam: Word;
  327.     lParam: Longint;
  328.   end;
  329.  
  330.   TMonCBStruct = record
  331.     cb: Word;
  332.     wReserved: Word;
  333.     dwTime: Longint;
  334.     hTask: THandle;
  335.     dwRet: Longint;
  336.     wType: Word;
  337.     wFmt: Word;
  338.     hConv: HConv;
  339.     hsz1: HSZ;
  340.     hsz2: HSZ;
  341.     hData: HDDEData;
  342.     dwData1: Longint;
  343.     dwData2: Longint;
  344.   end;
  345.  
  346.   TMonHSZStruct = record
  347.     cb: Word;
  348.     fsAction: Bool;    { mh_ value }
  349.     dwTime: Longint;
  350.     HSZ: HSZ;
  351.     hTask: THandle;
  352.     wReserved: Word;
  353.     Str: array[0..0] of Char;
  354.   end;
  355.  
  356. const
  357.   mh_Create = 1;
  358.   mh_Keep = 2;
  359.   mh_Delete = 3;
  360.   mh_Cleanup = 4;
  361.  
  362. type
  363.   PMonErrStruct = ^TMonErrStruct;
  364.   TMonErrStruct = record
  365.     cb: Word;
  366.     wLastError: Word;
  367.     dwTime: Longint;
  368.     hTask: THandle;
  369.   end;
  370.  
  371.   PMonLinkStruct = ^TMonLinkStruct;
  372.   TMonLinkStruct = record
  373.     cb: Word;
  374.     dwTime: Longint;
  375.     hTask: THandle;
  376.     fEstablished: Bool;
  377.     fNoData: Bool;
  378.     hszSvc: HSz;
  379.     hszTopic: HSz;
  380.     hszItem: HSz;
  381.     wFmt: Word;
  382.     fServer: Bool;
  383.     hConvServer: HConv;
  384.     hConvClient: HConv;
  385.   end;
  386.  
  387.   PMonConvStruct = ^TMonConvStruct;
  388.   TMonConvStruct = record
  389.     cb: Word;
  390.     fConnect: Bool;
  391.     dwTime: Longint;
  392.     hTask: THandle;
  393.     hszSvc: HSz;
  394.     hszTopic: HSz;
  395.     hConvClient: HConv;
  396.     hConvServer: HConv;
  397.   end;
  398.  
  399. const
  400.   max_Monitors = 4;
  401.   appClass_Monitor = 1;
  402.   xtyp_Monitor = $00F0 or xclass_Notification or xtypf_NoBlock;
  403.  
  404. const
  405. {
  406.  * Callback filter flags for use with MONITOR apps - 0 implies no monitor
  407.  * callbacks.
  408. }
  409.   mf_Hsz_Info = $01000000;
  410.   mf_SendMsgs = $02000000;
  411.   mf_PostMsgs = $04000000;
  412.   mf_CallBacks = $08000000;
  413.   mf_Errors = $10000000;
  414.   mf_Links = $20000000;
  415.   mf_Conv = $40000000;
  416.  
  417.  
  418. implementation
  419.  
  420. function DdeInitialize;                    external 'DDEML'    index 2;
  421. function DdeUninitialize;                  external 'DDEML'    index 3;
  422. function DdeConnectList;                   external 'DDEML'    index 4;
  423. function DdeQueryNextServer;               external 'DDEML'    index 5;
  424. function DdeDisconnectList;                external 'DDEML'    index 6;
  425. function DdeConnect;                       external 'DDEML'    index 7;
  426. function DdeDisconnect;                    external 'DDEML'    index 8;
  427. function DdeReconnect;                     external 'DDEML'    index 37;
  428. function DdeQueryConvInfo;                 external 'DDEML'    index 9;
  429. function DdeSetUserHandle;                 external 'DDEML'    index 10;
  430. function DdeAbandonTransaction;            external 'DDEML'    index 12;
  431. function DdePostAdvise;                    external 'DDEML'    index 13;
  432. function DdeEnableCallback;                external 'DDEML'    index 26;
  433. function DdeNameService;                   external 'DDEML'    index 27;
  434. function DdeClientTransaction;             external 'DDEML'    index 11;
  435. function DdeCreateDataHandle;              external 'DDEML'    index 14;
  436. function DdeAddData;                       external 'DDEML'    index 15;
  437. function DdeGetData;                       external 'DDEML'    index 16;
  438. function DdeAccessData;                    external 'DDEML'    index 17;
  439. function DdeUnaccessData;                  external 'DDEML'    index 18;
  440. function DdeFreeDataHandle;                external 'DDEML'    index 19;
  441. function DdeGetLastError;                  external 'DDEML'    index 20;
  442. function DdeCreateStringHandle;            external 'DDEML'    index 21;
  443. function DdeQueryString;                   external 'DDEML'    index 23;
  444. function DdeFreeStringHandle;              external 'DDEML'    index 22;
  445. function DdeKeepStringHandle;              external 'DDEML'    index 24;
  446. function DdeCmpStringHandles;              external 'DDEML'    index 36;
  447.  
  448. end.
  449.